package ModelLayer;
import java.util.*;

/**
 * Write a description of class DVD here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DVD
{
    // instance variables - replace the example below with your own
    private int id;
    private String title;
    private String artist;
    private String publicationDate;
    private HashSet<Copy> copies;

    /**
     * Constructor for objects of class DVD
     */
    public DVD()
    {
        copies=new HashSet<>();
        id=0;
        title=" ";
        artist=" ";
        publicationDate=" ";
    }

    public HashSet<Copy> readCopies()
    {
        return copies;
    }
    
    public int readSize()
    {
        return copies.size();
    }

    public int readNumberOfAvilableCopies()
    {
        int cont=0;
        Iterator<Copy> it = copies.iterator();
        while(it.hasNext()) 
        {
            Copy copy = it.next();
            if(copy.checkAvailable())
                {
                    cont++;
                }
        }
        return cont;
    }
    
    public void create(int id, String title, String artist, String publicationDate)
    {
        this.id=id;
        this.title=title;
        this.artist=artist;
        this.publicationDate=publicationDate;
    }
       
    public Boolean addCopy(int serialNumber, String purchaseDate, int price)
    {
        Iterator<Copy> it = copies.iterator();
        while(it.hasNext()) 
        {
            Copy copy = it.next();
            if(serialNumber==copy.readSerialNumber())
            return false;
        }
       Copy newCopy=new Copy();
       newCopy.create(serialNumber, purchaseDate, price);
       copies.add(newCopy);
       return true;
    }
    
    public Boolean removeCopy(int serialNumber)
    {
        Iterator<Copy> it = copies.iterator();
        while(it.hasNext()) 
        {
            Copy copy = it.next();
            if(serialNumber==copy.readSerialNumber())
            {
                copies.remove(copy);
                return true;
            }
        }
        return false;
    }
    
    public int readID()
    {
        return id;
    }
    
    public void updateID(int id)
    {
        this.id=id;
    }
    
    public String readTitle()
    {
        return title;
    }
    
    public void updateTitle(String title)
    {
        this.title=title;
    }
    
    public String readArtist()
    {
        return artist;
    }
    
    public void updateArtist(String artist)
    {
        this.artist=artist;
    }
    
    public String readPublicationDate()
    {
        return publicationDate;
    }
    
    public void updatePublicationDate(String publicationDate)
    {
        this.publicationDate=publicationDate;
    }
    
    
}
